/*
 * Flip - a visual programming language for scripting video games
 * Copyright (C) 2009, 2010 University of Sussex
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact the authors of this program, email flip@sussex.ac.uk.
 *
 * You can also write to Keiron Nicholson at the School of Informatics, 
 * University of Sussex, Sussex House, Brighton, BN1 9RH, United Kingdom.
 * 
 * This file added by Keiron Nicholson on 19/06/2010 at 12:58.
 */

using System;
using System.Windows;
using System.Windows.Controls;

namespace Sussex.Flip.UI
{
	/// <summary>
	/// Description of SizedCanvas.
	/// </summary>
	public class SizedCanvas : Canvas
	{
		public SizedCanvas() : base()
		{
		}
		
		
		protected override Size MeasureOverride(Size constraint)
		{
			Size desiredSize = base.MeasureOverride(constraint);
			
			foreach (UIElement child in Children) {
				desiredSize = new Size(Math.Max(desiredSize.Width, GetLeft(child) + child.DesiredSize.Width),
				                       Math.Max(desiredSize.Height, GetTop(child) + child.DesiredSize.Height));
			}
			
			return desiredSize; 
		}
	}
}